package ink.lovejinhu.swardToOffer;

public class Offer_021 {
    /**
     * 荷南国旗问题
     *
     * @param nums
     * @return
     */
    public int[] exchange(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            while (left<right&&nums[left] % 2 != 0) {
                left++;
            }
            while (left<right&&nums[right] % 2 == 0) {
                right--;
            }
            if (left < right) {
                this.swap(nums, left, right);
            }
        }

        return nums;
    }

    public void swap(int nums[], int left, int right) {
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }


}
